package com.example.textview.frament;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.textview.R;

public class AFragment extends Fragment {


    private TextView mtvtitle;
    Activity mactivity;
    Button mbtn_sendmsg;

    IOnMessageClick iOnMessageClicklistener;


//    public AFragment(String msg){
//
//
//    }


    public interface IOnMessageClick
    {
            void onCclik(String msg);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.fragment_a,container,false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mtvtitle=view.findViewById(R.id.tv_title);
        mbtn_sendmsg=view.findViewById(R.id.btn_sendMSG);
        mbtn_sendmsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iOnMessageClicklistener.onCclik("你好");
            }
        });
    }


    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
//        if(mactivity==null)
//        mactivity= (Activity) context;


            iOnMessageClicklistener= (IOnMessageClick) context;


    }


    @Override
    public void onDetach() {
        super.onDetach();
    }
}
